package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import java.util.HashMap;
import org.rsbot.bot.Bot;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Players;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSObject.Type;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

public class DrawObjects
  implements PaintListener
{
  private MethodContext ctx;
  private static final HashMap<RSObject.Type, Color> color_map = new HashMap();

  public DrawObjects(Bot paramBot)
  {
    this.ctx = paramBot.getMethodContext();
  }

  public void onRepaint(Graphics paramGraphics)
  {
    if (!this.ctx.game.isLoggedIn())
      return;
    RSPlayer localRSPlayer = this.ctx.players.getMyPlayer();
    if (localRSPlayer == null)
      return;
    FontMetrics localFontMetrics = paramGraphics.getFontMetrics();
    RSTile localRSTile1 = localRSPlayer.getLocation();
    int i = localRSTile1.getX();
    int j = localRSTile1.getY();
    int k = localFontMetrics.getHeight();
    for (int m = i - 25; m < i + 25; m++)
      for (int n = j - 25; n < j + 25; n++) {
        RSTile localRSTile2 = new RSTile(m, n);
        Point localPoint1 = this.ctx.calc.tileToScreen(localRSTile2);
        if (!this.ctx.calc.pointOnScreen(localPoint1)) {
          continue;
        }
        RSObject[] arrayOfRSObject1 = this.ctx.objects.getAllAt(localRSTile2);
        int i1 = 0;
        for (RSObject localRSObject : arrayOfRSObject1) {
          Point localPoint2 = this.ctx.calc.tileToScreen(localRSObject.getLocation());
          if (!this.ctx.calc.pointOnScreen(localPoint2)) {
            continue;
          }
          if (localPoint1.x > -1) {
            paramGraphics.setColor(Color.GREEN);
            paramGraphics.fillRect(localPoint1.x - 1, localPoint1.y - 1, 2, 2);
            paramGraphics.setColor(Color.RED);
            paramGraphics.drawLine(localPoint1.x, localPoint1.y, localPoint2.x, localPoint2.y);
          }
          String str = "" + localRSObject.getID();
          int i4 = localPoint2.y - k / 2 - i1++ * 15;
          int i5 = localPoint2.x - localFontMetrics.stringWidth(str) / 2;
          paramGraphics.setColor((Color)color_map.get(localRSObject.getType()));
          paramGraphics.drawString(str, i5, i4);
        }
      }
  }

  static
  {
    color_map.put(RSObject.Type.BOUNDARY, Color.BLACK);
    color_map.put(RSObject.Type.FLOOR_DECORATION, Color.YELLOW);
    color_map.put(RSObject.Type.INTERACTABLE, Color.WHITE);
    color_map.put(RSObject.Type.WALL_DECORATION, Color.GRAY);
  }
}